package com.wsx.java.boddy.interceptor;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers;

import java.util.List;


/**
 * @author wangshuaixin
 * @Title: com.wsx.java.boddy.interceptor.Main
 * @Description: TODO
 * @date 2019/01/23
 */
public class Main {

    public static void main(String[] args) throws Exception {
        MemoryDatabase database = new ByteBuddy()
                .subclass(MemoryDatabase.class)
                .method(ElementMatchers.named("load"))
                .intercept(MethodDelegation.to(LoggingInteceptor.class))
                .make()
                .load(Main.class.getClassLoader())
                .getLoaded()
                .newInstance();

        List<String> data = null;
        for (int i = 0; i < 10; i++) {
            data = database.load(i + "hello");
            data.forEach(s -> System.out.println(s));
        }
    }
}
